//
//  BGOriginalPicCell.swift
//  WeiboSwift
//
//  Created by 战场原黑仪 on 16/7/26.
//  Copyright © 2016年 战场原黑仪. All rights reserved.
//

import UIKit
import SDWebImage

class BGOriginalPicCell: UICollectionViewCell {

    //定义属性接收模型
    var pic_url: BGHomePictureModel? {
        didSet{
            bgImageView.bg_setImageWithURL(pic_url?.thumbnail_pic, placeholderImageName: "weibo_placeholder")
            
            //判断图片是否为GIF格式
            if let thPic = pic_url?.thumbnail_pic where thPic.hasSuffix(".gif"){
                gifImageView.hidden = false
            }else {
                gifImageView.hidden = true
            }
        }
    }
    
    override init(frame: CGRect) {
        super.init(frame: frame)
        setupUI()
        setupLayout()
    }
    
    required init?(coder aDecoder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }

    // MARK: - 设置视图
    private func setupUI(){
        contentView.addSubview(bgImageView)
        contentView.addSubview(gifImageView)
    }
    
    private func setupLayout(){
        bgImageView.snp_makeConstraints { (make) -> Void in
            make.edges.equalTo(contentView).offset(UIEdgeInsetsZero)
        }
        
        gifImageView.snp_makeConstraints { (make) -> Void in
            make.bottom.equalTo(contentView)
            make.trailing.equalTo(contentView)
        }
    }
    
    // MARK: - 懒加载控件
    // 背景图片
    private lazy var bgImageView: UIImageView = {
        let img = UIImageView(imageName: "weibo_placeholder")
        img.contentMode = .ScaleAspectFit
        img.layer.masksToBounds = true
        return img
    }()
    
    // 动态图片logo
    private lazy var gifImageView: UIImageView = UIImageView(imageName: "timeline_image_gif")
}